package org.easy.file.handler;

import cn.hutool.crypto.digest.DigestUtil;
import org.easy.tool.io.FileUtil;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @Description:
 * @Author: wxl
 * @CreateTime: 2022/12/29 9:54
 */
public class IFileParse implements FileParse{

    private final String fileId;

    private final File file;

    public IFileParse (File file) {
        this.file = file;
        this.fileId = DigestUtil.md5Hex(file);

    }

    /**
     * 获取文件
     *
     * @return file
     */
    @Override
    public File getFile() {
        return file;
    }

    /**
     * 获取文件ID
     *
     * @return String
     */
    @Override
    public String getFileId() {
        return fileId;
    }

    /**
     * 获取文件后缀
     *
     * @return String
     */
    @Override
    public String getFileSuffix() {
        return FileUtil.getSuffix(getFile());
    }

    /**
     * 文件内容
     *
     * @return List<String>
     */
    @Override
    public List<String> fileContents() {
        return FileUtil.readLines(getFile(), StandardCharsets.UTF_8);
    }
}
